/*
 * Copyright (c) 2016
 * 杭州塔酱科技有限公司 版权所有
 * Created by ${USER} on ${DATE}.
 */

package com.tajiang.business.model;

import java.util.List;

public class Pager<T> {

	private int totalPage;		//总页数
	private int totalCount;	//总记录数
	private int currentPage;	//当前页
	private int pagesize;		//每页的数量
	private int firstPage;
	private int prePage;
	private int nextPage;
	private int lastPage;
	private boolean isFirst;
	private boolean isLast;

	private String navigation; // 分页导航

	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPageCount() {
		return totalPageCount;
	}

	public void setTotalPageCount(int totalPageCount) {
		this.totalPageCount = totalPageCount;
	}

	private int page;
	private int pageSize;
	private int totalPageCount;

	private List<T> list;


	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPagesize() {
		return pagesize;
	}
	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}
	public int getFirstPage() {
		return firstPage;
	}
	public void setFirstPage(int firstPage) {
		this.firstPage = firstPage;
	}
	public int getPrePage() {
		return prePage;
	}
	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}
	public int getNextPage() {
		return nextPage;
	}
	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}
	public int getLastPage() {
		return lastPage;
	}
	public void setLastPage(int lastPage) {
		this.lastPage = lastPage;
	}
	public boolean isFirst() {
		return isFirst;
	}
	public void setFirst(boolean isFirst) {
		this.isFirst = isFirst;
	}
	public boolean isLast() {
		return isLast;
	}
	public void setLast(boolean isLast) {
		this.isLast = isLast;
	}
	public String getNavigation() {
		return navigation;
	}
	public void setNavigation(String navigation) {
		this.navigation = navigation;
	}

	/**
	 * 分页处理
	 * @param currentPage 当前页
	 * @param pageSize 每页的数量
	 * @param totalCount 总记录数
	 */
	public void paging(int currentPage, int pageSize, int totalCount){
		this.currentPage = currentPage;
		this.pagesize = pagesize;
		this.totalCount = totalCount;

		if(currentPage < 1){
			this.currentPage = 1;
		}

		this.totalPage = (this.totalCount + pagesize - 1)/pagesize;
		this.firstPage =1;
		this.lastPage = totalPage;

		if(this.currentPage > 1){
			this.prePage = this.currentPage - 1;
		}else{
			this.prePage = 1;
		}

		if(this.currentPage < totalPage){
			this.nextPage = this.currentPage + 1;
		}else{
			this.nextPage = totalPage;
		}

		if(this.currentPage <= 1){
			this.isFirst = true;
		}else{
			this.isFirst = false;
		}

		if(this.currentPage >= totalPage){
			this.isLast = true;
		}else{
			this.isLast = false;
		}
	}
	@Override
	public String toString() {
		return "Pager [totalPage=" + totalPage + ", totalCount=" + totalCount
				+ ", currentPage=" + currentPage + ", pagesize=" + pagesize
				+ ", firstPage=" + firstPage + ", prePage=" + prePage
				+ ", nextPage=" + nextPage + ", lastPage=" + lastPage
				+ ", isFirst=" + isFirst + ", isLast=" + isLast + ", list="
				+ list + ", navigation=" + navigation + "]";
	}


}
